<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 1000px;
            height: 600px;
            background: #000000;
            border: 5px solid red;
            margin: 20px auto;
            position: relative;
            overflow: hidden;
        }

        #box div {
            position: absolute;
            right: 50px;
            bottom: -50px;
            border-radius: 50%;
        }
    </style>
</head>

<body>
    <div id="box"></div>
</body>
<script>
    function star(id) {
        this.box = document.getElementById(id);
    }
    star.prototype.setStar = function () {
        var stars = document.createElement('div');
        var size = Math.floor(Math.random() * 31 + 20);
        var r = Math.floor(Math.random() * 256);
        var g = Math.floor(Math.random() * 256);
        var b = Math.floor(Math.random() * 256);
        stars.style.cssText = 'width:' + size + 'px;height:' + size + 'px;background:rgb(' + r + ',' + g + ',' + b + ')';
        stars.A = Math.floor(Math.random() * 50);
        stars.sb = Math.floor(Math.random() * 5 + 1);
        stars.b = -50;
        stars.o = 500;
        stars.timer = setInterval(function () {
            stars.b += stars.sb;
            stars.o -= stars.sb;
            if(stars.b>500){
                clearInterval(stars.timer)
                stars.remove();
            }
            var x = Math.sin(stars.b*Math.PI/180)*stars.A;
            stars.style.right = (x+50) + 'px';
            stars.style.bottom = stars.b + 'px';
            stars.style.opacity = stars.o/500;
        }, 10)

        this.box.appendChild(stars)
    }

    var s = new star('box');
    document.onclick = function(){
        s.setStar();
    }
</script>

</html>
